from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-09-14 14:12:49.201043
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 14, Sep, 2021
Time: 14:12:55
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -46.1569
Nobs: 414.000 HQIC: -46.6860
Log likelihood: 4538.68 FPE: 3.75185e-21
AIC: -47.0321 Det(Omega_mle): 3.02661e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.437755 0.093037 4.705 0.000
L1.Burgenland 0.103582 0.048091 2.154 0.031
L1.Kärnten -0.114171 0.024000 -4.757 0.000
L1.Niederösterreich 0.165568 0.103195 1.604 0.109
L1.Oberösterreich 0.120332 0.101164 1.189 0.234
L1.Salzburg 0.285703 0.050513 5.656 0.000
L1.Steiermark 0.023984 0.066950 0.358 0.720
L1.Tirol 0.108608 0.052913 2.053 0.040
L1.Vorarlberg -0.110771 0.047593 -2.327 0.020
L1.Wien -0.013440 0.092211 -0.146 0.884
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.014908 0.214777 0.069 0.945
L1.Burgenland -0.046906 0.111018 -0.423 0.673
L1.Kärnten 0.037678 0.055404 0.680 0.496
L1.Niederösterreich -0.212838 0.238227 -0.893 0.372
L1.Oberösterreich 0.486470 0.233538 2.083 0.037
L1.Salzburg 0.305678 0.116610 2.621 0.009
L1.Steiermark 0.113224 0.154555 0.733 0.464
L1.Tirol 0.314163 0.122149 2.572 0.010
L1.Vorarlberg 0.003221 0.109869 0.029 0.977
L1.Wien -0.003982 0.212871 -0.019 0.985
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.248185 0.047374 5.239 0.000
L1.Burgenland 0.090031 0.024488 3.677 0.000
L1.Kärnten -0.001605 0.012221 -0.131 0.896
L1.Niederösterreich 0.210195 0.052546 4.000 0.000
L1.Oberösterreich 0.168453 0.051512 3.270 0.001
L1.Salzburg 0.033663 0.025721 1.309 0.191
L1.Steiermark 0.018562 0.034091 0.544 0.586
L1.Tirol 0.066769 0.026943 2.478 0.013
L1.Vorarlberg 0.059556 0.024234 2.458 0.014
L1.Wien 0.107991 0.046954 2.300 0.021
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.181806 0.046269 3.929 0.000
L1.Burgenland 0.049180 0.023916 2.056 0.040
L1.Kärnten -0.006697 0.011936 -0.561 0.575
L1.Niederösterreich 0.135788 0.051321 2.646 0.008
L1.Oberösterreich 0.317243 0.050311 6.306 0.000
L1.Salzburg 0.100862 0.025121 4.015 0.000
L1.Steiermark 0.132661 0.033296 3.984 0.000
L1.Tirol 0.075451 0.026314 2.867 0.004
L1.Vorarlberg 0.057372 0.023669 2.424 0.015
L1.Wien -0.044010 0.045858 -0.960 0.337
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.207186 0.092016 2.252 0.024
L1.Burgenland -0.050544 0.047563 -1.063 0.288
L1.Kärnten -0.034955 0.023737 -1.473 0.141
L1.Niederösterreich 0.110845 0.102062 1.086 0.277
L1.Oberösterreich 0.173777 0.100053 1.737 0.082
L1.Salzburg 0.254247 0.049959 5.089 0.000
L1.Steiermark 0.078733 0.066215 1.189 0.234
L1.Tirol 0.124087 0.052332 2.371 0.018
L1.Vorarlberg 0.114330 0.047070 2.429 0.015
L1.Wien 0.026371 0.091199 0.289 0.772
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.028875 0.071201 0.406 0.685
L1.Burgenland 0.023848 0.036804 0.648 0.517
L1.Kärnten 0.052224 0.018367 2.843 0.004
L1.Niederösterreich 0.211358 0.078975 2.676 0.007
L1.Oberösterreich 0.336156 0.077420 4.342 0.000
L1.Salzburg 0.045421 0.038658 1.175 0.240
L1.Steiermark -0.006331 0.051237 -0.124 0.902
L1.Tirol 0.113414 0.040494 2.801 0.005
L1.Vorarlberg 0.066112 0.036423 1.815 0.070
L1.Wien 0.129737 0.070569 1.838 0.066
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.186823 0.087189 2.143 0.032
L1.Burgenland 0.017231 0.045068 0.382 0.702
L1.Kärnten -0.057343 0.022492 -2.550 0.011
L1.Niederösterreich -0.110783 0.096709 -1.146 0.252
L1.Oberösterreich 0.186781 0.094805 1.970 0.049
L1.Salzburg 0.031210 0.047338 0.659 0.510
L1.Steiermark 0.300237 0.062742 4.785 0.000
L1.Tirol 0.486208 0.049587 9.805 0.000
L1.Vorarlberg 0.070073 0.044602 1.571 0.116
L1.Wien -0.107397 0.086416 -1.243 0.214
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.160953 0.094891 1.696 0.090
L1.Burgenland -0.009878 0.049049 -0.201 0.840
L1.Kärnten 0.061755 0.024478 2.523 0.012
L1.Niederösterreich 0.187433 0.105251 1.781 0.075
L1.Oberösterreich -0.130460 0.103179 -1.264 0.206
L1.Salzburg 0.237062 0.051520 4.601 0.000
L1.Steiermark 0.159407 0.068284 2.334 0.020
L1.Tirol 0.052068 0.053967 0.965 0.335
L1.Vorarlberg 0.126444 0.048541 2.605 0.009
L1.Wien 0.158096 0.094049 1.681 0.093
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.486285 0.051387 9.463 0.000
L1.Burgenland -0.009836 0.026562 -0.370 0.711
L1.Kärnten -0.009835 0.013256 -0.742 0.458
L1.Niederösterreich 0.207580 0.056997 3.642 0.000
L1.Oberösterreich 0.262565 0.055875 4.699 0.000
L1.Salzburg 0.023052 0.027900 0.826 0.409
L1.Steiermark -0.025596 0.036978 -0.692 0.489
L1.Tirol 0.066526 0.029225 2.276 0.023
L1.Vorarlberg 0.056478 0.026287 2.149 0.032
L1.Wien -0.054181 0.050931 -1.064 0.287
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.021242 0.077612 0.141235 0.131362 0.040860 0.073698 -0.002055 0.174961
Kärnten 0.021242 1.000000 -0.045237 0.126906 0.046093 0.070189 0.455292 -0.094121 0.091819
Niederösterreich 0.077612 -0.045237 1.000000 0.284856 0.081475 0.266471 0.021655 0.137610 0.260897
Oberösterreich 0.141235 0.126906 0.284856 1.000000 0.180384 0.285600 0.156598 0.099104 0.139307
Salzburg 0.131362 0.046093 0.081475 0.180384 1.000000 0.125905 0.053773 0.101250 0.050006
Steiermark 0.040860 0.070189 0.266471 0.285600 0.125905 1.000000 0.131331 0.088899 -0.024843
Tirol 0.073698 0.455292 0.021655 0.156598 0.053773 0.131331 1.000000 0.039904 0.116369
Vorarlberg -0.002055 -0.094121 0.137610 0.099104 0.101250 0.088899 0.039904 1.000000 -0.049163
Wien 0.174961 0.091819 0.260897 0.139307 0.050006 -0.024843 0.116369 -0.049163 1.000000